/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ocumed.presentation.utils;

import java.util.HashMap;
import javax.swing.DefaultListModel;

/**
 *
 * @author apr3455
 */
public class StdListModel extends DefaultListModel implements SortableModel {
    private HashMap<Integer, String> m_hashMap = null;
    protected Object[] m_ids = null;
    protected Object[] m_values = null;
    private Integer m_size = null;
    
    public StdListModel(HashMap<Integer, String> hashMap){
        ListSort listSort = new ListSort();
        m_size = hashMap.size();
        m_hashMap = hashMap;
        m_ids = m_hashMap.keySet().toArray();
        m_values = hashMap.values().toArray();
        listSort.sortArray(m_values, this);
    }
    
    public void changeIdPos(int i, int j){
        Object temp = m_ids[i];
        m_ids[i] =  m_ids[j];
        m_ids[j] = temp;
    }
    
    @Override
    public int getSize() {
        return m_size;
    }

    @Override
    public Object getElementAt(int pos) {
        int p = (Integer) m_ids[pos];
        return m_hashMap.get(p);
    }

    public Object getIdAt(int pos){
        return m_ids[pos];
    }
    
    public Integer getIdByListPos(int pos){
        return (Integer) m_ids[pos];
    }
    
}
